package cn.funeralobjects.dictms.repository;

import cn.funeralobjects.common.repository.CommonCloudRepository;
import cn.funeralobjects.dictms.entity.EDictValue;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.util.Optional;

/**
 * @author FuneralObjects
 * Create date: 2020/6/2 11:27 PM
 */
public interface EDictValueRepository extends CommonCloudRepository<EDictValue, Integer>, JpaSpecificationExecutor<EDictValue> {

    /**
     * where dict_id = #{dictId} and value = #{value} and del_salt = #{delSalt}
     *
     * @param dictId  ${dictId}
     * @param value   #{value}
     * @param delSalt #{delSalt}
     * @return select count(*) > 0 ?
     */
    boolean existsAllByDict_IdAndValueAndDelSalt(Integer dictId, String value, Integer delSalt);

    /**
     * where dict_id = #{dictId} and value = #{value} and del_salt = #{delSalt} and id <> ${id}
     *
     * @param dictId  ${dictId}
     * @param value   #{value}
     * @param delSalt #{delSalt}
     * @param id      id
     * @return select count(*) > 0 ?
     */
    boolean existsAllByDict_IdAndValueAndDelSaltAndIdNot(Integer dictId, String value, Integer delSalt, Integer id);

    /**
     * where id = ${id} and dict_id = #{dictId} and del_salt = #{delSalt}
     *
     * @param id      ${id}
     * @param dictId  ${dictId}
     * @param delSalt ${delSalt}
     * @return select count(*) > 0 ?
     */
    boolean existsAllByIdAndDict_IdAndDelSalt(Integer id, Integer dictId, Integer delSalt);

    /**
     * where dict_id = ${dictId} and value = ${value} and del_salt = ${delSalt} limit 0,1
     *
     * @param dictId  ${dictId}
     * @param value   ${value}
     * @param delSalt ${delSalt}
     * @return select *
     */
    Optional<EDictValue> findFirstByDict_IdAndValueAndDelSalt(Integer dictId, String value, Integer delSalt);

    /**
     * where dict_id = ${dictId} and id = ${id} and del_salt = ${delSalt} limit 0,1
     *
     * @param dictId  ${dictId}
     * @param id      ${id}
     * @param delSalt ${delSalt}
     * @return select *
     */
    Optional<EDictValue> findFirstByDict_IdAndIdAndDelSalt(Integer dictId, Integer id, Integer delSalt);
}
